#ifndef __INClogh
#define __INClogh
#include <type.h>
#include <modules.h>
#include <logMgr.h>
#include <posix.h>
    
#ifndef CURRENT_LOG_ID
    #define CURRENT_LOG_ID MODULE_ALL
#endif
#define LVOS_Log(level, ...)   logWrite(CURRENT_LOG_ID, level, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define LOG_DBG(format, ...)   LVOS_Log(LOG_LVL_DEBUG, format, ##__VA_ARGS__)
#define LOG_INFO(format, ...)  LVOS_Log(LOG_LVL_INFO,  format, ##__VA_ARGS__)
#define LOG_WARN(format, ...)  LVOS_Log(LOG_LVL_WARN,  format, ##__VA_ARGS__)
#define LOG_ERROR(format, ...) LVOS_Log(LOG_LVL_ERROR, format, ##__VA_ARGS__)
#define LOG_FATAL(format, ...) LVOS_Log(LOG_LVL_FATAL, format, ##__VA_ARGS__)
#define LOG_TRACE(format, ...) LVOS_Log(LOG_LVL_TRACE, format, ##__VA_ARGS__)
#define LVOS_DUMP(name, width, buf, size) Ilog::logHexdump(CURRENT_LOG_ID, name, width, buf, size)
#define LVOS_ASSERT(EXPR)                                  \
    if ((EXPR))                                            \
    {                                                      \
        LOG_FATAL("(%s) has assert failed at %s:%ld.",     \
                    #EXPR, __FUNCTION__, __LINE__);        \
        while (1);                                         \
    }

// Conditional check return value
#define COND_CHECK_LOG_RET_VAL(_cond, _retVal, _fmt, ...)  \
    do                                                     \
    {                                                      \
        if (_UNLIKELY((_cond)))                            \
        {                                                  \
            LOG_ERROR("Check condition failed: %s, " _fmt, \
                    #_cond, ##__VA_ARGS__);                \
            return _retVal;                                \
        }                                                  \
    } while (0)

#define COND_CHECK_RET_ERROR(_cond) COND_CHECK_RET_VAL(_cond, RET_ERROR)

#endif // __INClogh
